-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix circuit reversal in stratified_circuit in cirq-core/cirq/transformers/stratify.py #7531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Wasn't sure about modifying in place vs returning a modified circuit, I can switch the approach if returning a modified circuit would be better. Also, I am new to open source contributions, so any input or nitpicks are appreciated. |
I'd say call the function "reversed" and make it return a copy, and put it on AbstractCircuit instead of just Circuit. . Also probably do the same thing on Moment, and try to have it maintain the cached member fields instead of regenerating them, to avoid the perf hit. In AbstractCircuit's reversed method, an optional bool "preserve_operation_order_in_moments=False" parameter to make it explicit that the moment internal structure also gets reversed by default. You can go ahead and update align_right to use this too, but I'd probably not go further than that as far as backporting in a single PR. |
Is there a use case for preserving the order of operations in the moments? If not, would a more verbose function name serve this purpose better? I'm planning on opening a new issue to look for other instances where this new reversal can be used, I'll put the align_right change into that pr to maintain granularity. |
Yeah, on second thought, don't bother with the extra parameter. If someone wants to just reverse moments then they can use the slice notation, so no need to add explicit support for that here too. |
@wang-anthony03 Thank you for your work on this. Would you be able to take a look at the test failures and address the problems? |
I am removing the |
Fixes #7474.
stratified_circuit
reversed circuits by reversing the moments in the circuit, without reversing the operations in the moment, causing measurement errors.In order to fix this, a
circuit.reverse()
was created, following #6899, and used instratified_circuit
to ensure no measurement errors occurred because of the reversed circuit.